package com.svse.designPattern.behaviour.iterator.impl;

import com.svse.designPattern.behaviour.iterator.service.Iterator;

import java.util.List;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2020/8/8 23:07
 */
public class ConcreteIterator  implements Iterator {
    private List<Object> list=null;
    private int index=-1;
    public ConcreteIterator(List<Object> list) {
        this.list = list;
    }

    @Override
    public Object first() {
        index=0;
        return list.get(index);
    }

    @Override
    public Object next() {
        Object obj=null;
        if(this.hasNext()){
            obj=list.get(++index);
        }
        return obj;
    }

    @Override
    public boolean hasNext() {
        if(index<list.size()-1){
            return true;
        }else{
            return false;
        }
    }
}
